#include <algorithm>
#include <iostream>

using namespace std;

struct farmer {
    int prc, res;
    farmer() : prc(0), res(0) {}
    farmer(int p, int r) : prc(p), res(r) {}
};

bool cmp(farmer d1, farmer d2) { return d1.prc < d2.prc; }
int max(int a, int b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }

int n, m, ans = 0;
farmer d[6000];

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> d[i].prc >> d[i].res;
    sort(d, d + m, cmp);
    int j = 0;
    while (n > 0) {
        ans += min(n, d[j].res) * d[j].prc;
        n -= min(n, d[j].res);
        j++;
    }
    cout << ans;
}